import java.awt.EventQueue;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.AbstractAction;
import java.awt.event.ActionEvent;
import javax.swing.Action;
import java.awt.event.ActionListener;
import java.beans.XMLEncoder;
import java.io.FileOutputStream;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;


public class ConfigurationFrame {

	private JFrame frame;
	private JTextField textFilter;
	private Configuration configuration;//=new Configuration();
	public final ButtonGroup protocolGroup = new ButtonGroup();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ConfigurationFrame window = new ConfigurationFrame();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public ConfigurationFrame() {
		try {
			initialize();
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * Initialize the contents of the frame.
	 * @throws SocketException 
	 */
	private void initialize() throws SocketException {
		frame = new JFrame();
		frame.setBounds(100, 100, 373, 363);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JButton btnOk = new JButton("OK");
		btnOk.setBounds(10, 288, 89, 23);
		frame.getContentPane().add(btnOk);
		
		JButton btnSave = new JButton("Save");
		btnSave.setBounds(138, 288, 89, 23);
		frame.getContentPane().add(btnSave);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.setBounds(258, 288, 89, 23);
		frame.getContentPane().add(btnCancel);
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Protocol Filter", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(10, 77, 337, 82);
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		JCheckBox chckbxTcp = new JCheckBox("TCP");
		protocolGroup.add(chckbxTcp);
		chckbxTcp.setBounds(6, 19, 56, 23);
		panel.add(chckbxTcp);
		
		JCheckBox chckbxUdp = new JCheckBox("UDP");
		protocolGroup.add(chckbxUdp);
		chckbxUdp.setBounds(64, 19, 62, 23);
		panel.add(chckbxUdp);
		
		JCheckBox chckbxIp = new JCheckBox("IP");
		protocolGroup.add(chckbxIp);
		chckbxIp.setBounds(186, 19, 56, 23);
		panel.add(chckbxIp);
		
		JCheckBox chckbxHttp = new JCheckBox("HTTP");
		protocolGroup.add(chckbxHttp);
		chckbxHttp.setBounds(128, 19, 56, 23);
		panel.add(chckbxHttp);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(null, "Network Interface", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_1.setBounds(10, 11, 337, 55);
		frame.getContentPane().add(panel_1);
		panel_1.setLayout(null);
		
		JComboBox<String> comboBox = new JComboBox<String>();
		comboBox.setBounds(10, 21, 317, 20);
		Enumeration<NetworkInterface> list=configuration.getDevList();
		int count=0;
		for(NetworkInterface device :Collections.list(list))
		{
			if(device.isUp())
				comboBox.addItem(device.getDisplayName());
		}
		panel_1.add(comboBox);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "IP Filtering", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_2.setBounds(10, 170, 337, 97);
		frame.getContentPane().add(panel_2);
		panel_2.setLayout(null);
		
		JRadioButton rdbtnFilter = new JRadioButton("Filter");
		rdbtnFilter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textFilter.setEnabled(true);
			}
		});
		rdbtnFilter.setBounds(16, 24, 63, 23);
		panel_2.add(rdbtnFilter);
		
		JRadioButton rdbtnAllIps = new JRadioButton("All IPs");
		rdbtnAllIps.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				textFilter.setEnabled(false);
			}
		});
		rdbtnAllIps.setSelected(true);
		rdbtnAllIps.setBounds(78, 24, 77, 23);
		ButtonGroup ipFiltering=new ButtonGroup();
		ipFiltering.add(rdbtnAllIps);
		ipFiltering.add(rdbtnFilter);
		panel_2.add(rdbtnAllIps);
		
		textFilter = new JTextField();
		textFilter.setEnabled(false);
		if(rdbtnFilter.isSelected())
		{
			textFilter.setEnabled(true);
		}
		textFilter.setBounds(16, 54, 312, 20);
		panel_2.add(textFilter);
		textFilter.setColumns(10);
	}
	private class SwingAction extends AbstractAction {
		public SwingAction() {
			putValue(NAME, "SwingAction");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}
		public void actionPerformed(ActionEvent e) {
		}
	}
}
